<?php
$page = 1;
if(isset($_GET['page'])) {
	$page = $_GET['page'];
}

$typeNew = "";
if (!isset($_GET['type'])) {
	return;
}
$typeNew = $_GET['type'];
$dataTypeNew = getTypeDuAnByID($typeNew);

if (count($dataTypeNew) < 1) {
	return;
}

$arrcountrows = getRowsDuAnIndex($typeNew);
$sumrecord = $arrcountrows[0][0];
$numrecord = 12;
$pageNumber = intval(($sumrecord / $numrecord));
if(($sumrecord % $numrecord) != 0) {
	$pageNumber++;
}

if($pageNumber == 0) {
	$pageNumber = 1;	
}

if($page > $pageNumber) {
	$page = $pageNumber;
}
$products = getDuAnsLimitIndex($typeNew, ($page-1)*$numrecord, $numrecord);

?>
<div itemscope itemtype="" id="crumbs"> <a class="crumbs-home" itemprop="breadcrumb" href="/">Home</a> » <a itemprop="breadcrumb" href="/du-an.html" title="Dự án">Dự án</a> »  <span class="current"><?php echo($dataTypeNew[0][1]); ?></span></div>
<div class="page-head">
	<h2 class="page-title"><span> <?php echo($dataTypeNew[0][1]); ?></span></h2>
    <a class="rss-cat-icon ttip" title="Feed Subscription" href="#">Feed Subscription</a>
    <div class="stripe-line"></div>
    <div class="clear"></div>
    <div class="archive-meta"></div>
</div>

<div class="post-listing">

<?php
foreach ($products as $entry) {
?>	
	<article class="item-list">
		<h2><a href="/du-an/<?php echo($entry[0]); ?>/<?php echo(rewriteTextUrl(stripUnicode($entry[3]))); ?>.html" title="<?php echo($entry[3]); ?>" rel="bookmark"><?php echo($entry[3]); ?></a></h2>
		<p class="post-meta">
        	<span><?php echo(int_to_date($entry[8])); ?></span>
		</p>
		<div class="post-thumbnail">
			<a href="/du-an/<?php echo($entry[0]); ?>/<?php echo(rewriteTextUrl(stripUnicode($entry[3]))); ?>.html" title="<?php echo($entry[3]); ?>" rel="bookmark">
				<img width="168" height="108" src="<?php echo($entry[4]); ?>" class="attachment-thumbnail" alt="<?php echo($entry[3]); ?>" />
			</a>
		</div><!-- post-thumbnail /-->
        
		<div class="entry">
			<p><?php echo($entry[5]); ?> ...			<a class="more-link" href="/du-an/<?php echo($entry[0]); ?>/<?php echo(rewriteTextUrl(stripUnicode($entry[3]))); ?>.html">Chi Tiết &raquo;</a></p>
		</div>
        <div class="clear"></div>
	</article><!-- .item-list -->
<?php 
}
?>	
	<!-- .item-list -->
	
</div>
<div class="pagination">
	<span class="pages">Trang <?php echo($page); ?>/<?php echo($pageNumber); ?></span>
    <?php
	$i = 1;
	for ($i = 1; $i <= $pageNumber; $i++) {
		if ($page == $i) {
			?>
    <span class="current"><?php echo($i); ?></span>        
            <?php
		} else {
			?>
    <a href="/du-an/danhmuc/<?php echo($dataTypeNew[0][0]); ?>/<?php echo(rewriteTextUrl(stripUnicode($dataTypeNew[0][1]))); ?>/page/<?php echo($i); ?>.html" class="page" title="<?php echo($i); ?>"><?php echo($i); ?></a>
            <?php
		}
	}
	
	if ($page != $pageNumber) {
	?>
    <span id="tie-next-page">
    	<a href="/du-an/danhmuc/<?php echo($dataTypeNew[0][0]); ?>/<?php echo(rewriteTextUrl(stripUnicode($dataTypeNew[0][1]))); ?>/page/<?php echo($i); ?>.html" >&raquo;</a>
	</span>
    <?php 
	}
	?>
</div>